import {Component, OnInit} from '@angular/core';
import {STColumn} from '@delon/abc';
import {BaseService} from '@sb/base';
import {HyProjectService} from '../service/hy-project.service';
import {SFSchema, SFTextareaWidgetSchema} from '@delon/form';
import {NzMessageService} from 'ng-zorro-antd';
import {
    SysRegionSelectAlainComponent,
    SysRegionSelectAlainSchema
} from "../../../system/sys/sys-region/sys-region-select-alain/sys-region-select-alain.component";
import {OuOrgUserTreeSelectAlainSchema} from "../../../system/ou/ou-org-user-tree-select-alain/ou-org-user-tree-select-alain.component";
import {SysCodeSelectAlainSchema} from "../../../system/sys/sys-code/sys-code-select-alain/sys-code-select-alain.component";

@Component({
    selector: 'hy-project',
    templateUrl: './hy-project.component.html',
    styleUrls: ['./hy-project.component.less'],
    providers: [
        {
            provide: BaseService,
            useClass: HyProjectService
        }
    ]
})
export class HyProjectComponent implements OnInit {

    columns: STColumn[] = [
        {
            title: '',
            type: 'checkbox',
            index: 'projectId'
        }, {
            title: '项目名称',
            index: 'name',
            width: '15%'
        },{
            title: '项目负责人',
            index: 'managerUserName',
            width: '15%'
        },{
            title: '所属地区',
            index: 'mc',
            className: 'text-center word-wrap',
            width: '30%',
            format: (v) => {
                let sheng = v['provinceName'] || '';
                let shi = v['cityName'] || '';
                let qu = v['districtName'] || '';
                return sheng + shi + qu;
            }
        }

    ];

    schema: SFSchema = {
        properties: {
            name: {
                type: 'string',
                title: '项目名称',
                minLength: 2
            },
            type: {
                type: 'string',
                title: '项目类型',
                minLength: 2,
                ui: {
                    widget: 'sys-code-select-alain2',
                    category: 'PROJECT_TYPE',
                } as SysCodeSelectAlainSchema
            },
            managerUserId: {
                type: 'string',
                title: '项目负责人',
                ui: {
                    widget: 'ou-org-user-tree-select-alain',
                    searchConfig: {
                        searchUser: true,
                        searchSubOrg: true,
                        searchDept: true
                    }
                } as OuOrgUserTreeSelectAlainSchema
            },
            planStartDate: {
                type: 'string',
                title: '计划开始日期',
                format: 'date',
                minLength: 2
            },
            planEndDate: {
                type: 'string',
                title: '计划结束日期',
                format: 'date',
                minLength: 2
            },
            xzq: {
                type: 'string',
                title: '行政区',
                ui: {
                    widget: SysRegionSelectAlainComponent.KEY,
                    aboveTopLevelCode: '100000',
                    showProvince: true,
                    showCity: true,
                    showDistrict: true,
                    eachWidth: '33%',
                    valueType: 'array'
                } as SysRegionSelectAlainSchema
            },
            description: {
                type: 'string',
                title: '项目描述',
                ui: {
                    autosize: {
                        minRows: 3,
                        maxRows: 6
                    }
                } as SFTextareaWidgetSchema
            },
        },
        required: ['name']
    };

    constructor(
        private message: NzMessageService) {
    }

    ngOnInit(): void {
    }
}
